from past.builtins import raw_input

numbers = [1, 2, 3, 4, 5]
even = []
odd = []
l = len(numbers)
while l > 0:  # 只要是True，里面的代码块会一直执行
    number = numbers.pop()  # 从末尾弹出元素 numbers[index]
    l -= 1  # l=l-1
    print('current length :%s' % l)
    if number % 2 == 0:
        even.append(number)
    else:
        odd.append(number)
print(even)
print(odd)

'''
continue、break
  continue 用于跳过该次循环，break 则是用于退出循环
'''

i = 1
while i < 10:
    i += 1
    if i % 2 != 0:  # 奇数时跳过输出
        continue
    print(i)  # 输出双数2、4、6、8、10
print('*' * 10)
i = 1
while 1:  # 循环条件为1必定成立,等于while True
    print(i)  # 输出1~10
    i += 1
    if i > 3:  # 当i大于10时跳出循环
        break

'''
while else 一般不太用
'''

count = 0
while count < 5:
    print(count, " is  less than 5")
    count = count + 1
else:
    print(count, " is not less than 5")

'''
猜拳小游戏
'''
import random

while 1:
    s = int(random.randint(1, 3))
    if s == 1:
        ind = "石头"
    elif s == 2:
        ind = "剪子"
    elif s == 3:
        ind = "布"
    m = raw_input('输入 石头、剪子、布,输入"end"结束游戏:')
    blist = ['石头', "剪子", "布"]
    if (m not in blist) and (m != 'end'):
        print("输入错误，请重新输入！")
    elif (m not in blist) and (m == 'end'):
        print("\n游戏退出中...")
        # i = 1 / 0 也可以使用异常退出
        break
    elif m == ind:
        print("电脑出了： " + ind + "，平局！")
    elif (m == '石头' and ind == '剪子') or (m == '剪子' and ind == '布') or (m == '布' and ind == '石头'):
        print("电脑出了： " + ind + "，你赢了！")
    elif (m == '石头' and ind == '布') or (m == '剪子' and ind == '石头') or (m == '布' and ind == '剪子'):
        print("电脑出了： " + ind + "，你输了！")
